package guet.dream.qa;

import guet.dream.db.DatabaseUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;

public class QuestionAnswerDaoImpl implements QuestionAnswerDao {


	public int saveAnswerByQuestionId(int qid, String content) {
	String queryString = "insert into answers(question_id,content) values(?,?)";
		
		Connection con = DatabaseUtils.getConnection();
		try {
			PreparedStatement pstmt = con.prepareStatement(queryString);
			pstmt.setInt(1, qid);
			pstmt.setString(2, content);
			//利用mysql的current特性.而不自己获取值了.
		//	pstmt.setTimestamp(3,new Timestamp(System.currentTimeMillis()));
				
			boolean flag = pstmt.execute();
			int count = pstmt.getUpdateCount();
			
			return count;
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
		
	}



}
